
#include "tbb/atomic.h"


template<typename T>
class lazy {
        tbb::atomic<T*> value;
public:
        lazy(){value=NULL;}

        ~lazy() {delete value;}

        T& get() {
                if( !value ) {
                        T* tmp = new T();
                        if( value.compare_and_swap(tmp,NULL)!=NULL )
                                // Another thread installed the value, so throw away mine.
                                delete tmp;
                }
                return *value.operator->();
        }
};

struct A{};


int main(int argc,char** argv){

        lazy<int> x;
        int y;
        y = x.get();        

        return 0;
}
